{extend name="common/layout" /}

{block name="body"}
<div class="container">
    <div class="layui-form">
        <!-- 服务协议 -->
        <div class="layui-card">
            <div class="layui-tab layui-tab-card">
                <ul class="layui-tab-title">
                    <li class="layui-this">服务协议</li>
                    <li>隐私政策</li>
                </ul>
                <div class="layui-tab-content" style="padding: 15px;">
                    <!-- 1、服务协议 -->
                    <div class="layui-tab-item layui-show">
                        <label for="service"><textarea id="service" name="service">{$detail.service ?? ''}</textarea></label>
                    </div>
                    <!-- 2、隐私政策 -->
                    <div class="layui-tab-item">
                        <label for="privacy"><textarea id="privacy" name="privacy">{$detail.privacy ?? ''}</textarea></label>
                    </div>
                </div>
            </div>
        </div>
        <!-- 保存配置 -->
        <div class="layui-card">
            <div class="layui-card-body">
                <button class="layui-btn layui-btn-default {:check_perms('save', false)}" lay-submit lay-filter="addForm">保存配置</button>
            </div>
        </div>
    </div>
</div>
{/block}

{block name="js"}
<script>
    layui.use(['form', 'tinymce'], function () {
        let form = layui.form;
        let tinymce = layui.tinymce;

        tinymce.render({elem: '#service'});
        tinymce.render({elem: '#privacy'});

        form.on('submit(addForm)', function() {
            let service = tinymce.get('#service').getContent();
            let privacy = tinymce.get('#privacy').getContent();

            service = service.replace("<!DOCTYPE html>\n<html>\n<head>\n</head>\n<body>\n", '');
            service = service.replace("</body>\n</html>", '');
            privacy = privacy.replace("<!DOCTYPE html>\n<html>\n<head>\n</head>\n<body>\n", '');
            privacy = privacy.replace("</body>\n</html>", '');

            layer.confirm('确定保存设置的内容吗？', function() {
                waitUtil.ajax({
                    url: '{:route("setting.policy/save")}',
                    type: 'POST',
                    data: {service:service, privacy:privacy}
                });
            });
        });
    });
</script>
{/block}